﻿/* 变量 */
var orderList = "user/orderList.html";
var orderDetail = "user/orderDetail.html";
var pborderlist = "user/panicBuyingOrderList.html";

var current_tabindex = 0;
var contactsCallback_orderList_back = myApp.onPageBeforeAnimation('orderlist', function (page) {
    var isfresh = iss_localStorage.get("yuqing_isfresh");
    var orderType = ISS.utils.getParameter("orderType");
    if (page != undefined) {
        orderType = page.query.orderType;
    }
    if (isfresh != "true" || orderType != 0) {
        return;
    }

    // 全局变量
    var _userID = iss_localStorage.get("yuqing_appUserId");

    //点击第一次页面执行
    var flag_order_tab1 = true;
    //当前tab标签，0：已付款 1：待付款 2：全部

    //定义每页的页数
    var size = 10;
    //每个tab的当前页
    var index_tab0 = 1;
    var index_tab1 = 1;
    var index_tab2 = 1;
    //删除滚动后重新添加滚动
    var flag_InfiniteScroll = true;
    //是否需要滚动加载
    var flag_needScroll = true;
    //滚动事件只执行一次
    var flag_execute = false;
    //第一次加载显示index_tab1，已付款的
    if (flag_order_tab1 == true) {
        $$("#sub_orderList_tab1 .list-block ul").html("");
        $$("#sub_orderList_tab2 .list-block ul").html("");
        $$("#sub_orderList_tab3 .list-block ul").html("");
        LoadOrderAll(index_tab0, current_tabindex);
        iss_localStorage.set("yuqing_isfresh", "false");
        flag_order_tab1 = false;
    }

    // //订单类型切换
    // $$(".sub_buttons_row a").click(function () {
    //     $$('.infinite-scroll').scrollTop(0);
    //     current_tabindex = $$(this).index();
    //     //加载无限滚动事件
    //     myApp.attachInfiniteScroll($$('.infinite-scroll'));

    //     //        if ($$(this).index() == 0 && $$("#sub_orderList_tab1 ul").children("li").length == 0) {
    //     //            LoadOrderAll(index_tab0, current_tabindex);
    //     //        }
    //     //        else if ($$(this).index() == 1 && $$("#sub_orderList_tab2 ul").children("li").length == 0) {
    //     //            LoadOrderAll(index_tab1, current_tabindex);
    //     //        }
    //     //        else if ($$(this).index() == 2 && $$("#sub_orderList_tab3 ul").children("li").length == 0) {
    //     //            LoadOrderAll(index_tab2, current_tabindex);
    //     //        }
    //     //modify by changlishuang 2016-08-12 只要切换table数据不为空，也重新加载数据
    //     if ($$(this).index() == 0) {
    //         index_tab0 = 1;
    //         LoadOrderAll(index_tab0, current_tabindex);
    //     }
    //     else if ($$(this).index() == 1) {
    //         index_tab1 = 1;
    //         LoadOrderAll(index_tab1, current_tabindex);
    //     }
    //     else if ($$(this).index() == 2) {
    //         index_tab2 = 1;
    //         LoadOrderAll(index_tab2, current_tabindex);
    //     }
    // });

    //加载数据
    function LoadOrderAll(pageindex, currentIndex) {
        // 检索条件
        var v_search = [];
        //类型: 0:景区,1:酒店,2：线路,22:团购

        v_search.push({
            SearchField: "OrderType",
            ListSearchValue: [
                {
                    ItemValue: orderType
                }
            ]
        });


        //来源
        v_search.push({
            SearchField: "SourceType",
            ListSearchValue: [
                {
                    ItemValue: "2"
                }
            ]
        });
        //用户
        v_search.push({
            SearchField: "UserID",
            ListSearchValue: [{
                ItemValue: _userID
            }]
        });
        //订单状态标签页，2是全部，不需要加条件
        if (currentIndex == 0) {
            //状态
            v_search.push({
                SearchField: "OrderStatus",
                ListSearchValue: [
                    {
                        ItemValue: 4//已支付
                    }
                ]
            });
        }
        else if (currentIndex == 1) {
            v_search.push({
                SearchField: "OrderStatus",
                ListSearchValue: [
                    {
                        ItemValue: 2//待付款
                    }
                ]
            });
        }

        // 排序
        var v_order = [];
        //事件
        var opt = {
            OrderField: "orderTime",
            OrderType: "desc"
        };
        v_order.push(opt);

        //JSON
        var OrderListContent = JSON.stringify({
            type: 0,
            conditionParams: {
                "Page": { "PageSize": size, "PageIndex": pageindex },
                Search: v_search,
                Order: v_order
            }

        });
        myApp.showPreloader();
        $$.ajax({
            url: ISS_Constants.Url.defaulturl + ISS_Constants.serviceName.ORDERS,
            data: { content: OrderListContent },
            dataType: "jsonp",
            method: "POST",
            success: function (data, status) {
                myApp.hidePreloader();
                data = JSON.parse(data);
                if (data && data.results && data.results.length > 0) {
                    //循环每一个订单,处理数据
                    for (var i = 0; i < data.results.length; i++) {
                        //图片处理
                        if (data.results[i].orderPhoto == null || data.results[i].orderPhoto == "") {
                            data.results[i].orderPhoto = NoPicture();
                        };
                        //订单状态，数字转换汉字描述
                        data.results[i] = formatData(data.results[i]);
                        //获取订单orderNumber，订单对应产品数量
                        if (data.results[i].getHotelOrderInfo.length > 0) {
                            data.results[i].orderNumber = data.results[i].getHotelOrderInfo[0].orderNumber;
                        }
                        else if (data.results[i].getLineOrderInfo.length > 0) {
                            data.results[i].orderNumber = data.results[i].getLineOrderInfo[0].orderNumber;
                        }
                        else if (data.results[i].getTicketOrderInfo.length > 0) {
                            data.results[i].orderNumber = data.results[i].getTicketOrderInfo.length;//data.results[i].getTicketOrderInfo[0].orderNumber;
                        }
                        else if (data.results[i].getGroupOrder.length > 0) {
                            data.results[i].orderNumber = data.results[i].getGroupOrder[0].orderNo
                        }
                        //修改酒店订单，修改每天的房间的开始结束日期格式
                        for (var j = 0; j < data.results[i].getHotelOrderInfo.length; j++) {
                            data.results[i].getHotelOrderInfo[j].ARRIVALDATE = toDateFormat(data.results[i].getHotelOrderInfo[j].ARRIVALDATE);
                            data.results[i].getHotelOrderInfo[j].FINISHEDDATE = toDateFormat(data.results[i].getHotelOrderInfo[j].FINISHEDDATE);
                        }
                        //修改门票订单，修改游玩时间的开始结束日期格式
                        for (var j = 0; j < data.results[i].getTicketOrderInfo.length; j++) {
                            data.results[i].getTicketOrderInfo[j].playDate = toDateFormat(data.results[i].getTicketOrderInfo[j].playDate);
                        }
                        for (var j = 0; j < data.results[i].getGroupOrder.length; j++) {
                            data.results[i].getGroupOrder[j].createDate = toDateFormat(data.results[i].getGroupOrder[j].createDate);
                            data.results[i].getGroupOrder[j].toDay = toDateFormat(data.results[i].getGroupOrder[j].toDay);
                        }
                    }
                    //根据订单类型，获取模板页
                    var searchTemplate;
                    if (orderType == "0") {
                        searchTemplate = $$('#template-orderList-ticket').html();
                    }
                    else if (orderType == "1") {
                        searchTemplate = $$('#template-orderList-hotel').html();
                    }
                    //这里应该是线路，只是现在线路没有做，先调用门票的
                    else if (orderType == "2") {
                        searchTemplate = $$('#template-orderList-line').html();
                    }
                    else if (orderType == "22") {
                        searchTemplate = $$('#template-orderList-Group').html();
                    }

                    if (searchTemplate) {
                        var compiledTemplate = Template7.compile(searchTemplate);
                        var html = compiledTemplate(data);
                        //current_tab_index 已付款
                        if (currentIndex == 0) {
                            //因为每次点击tab都会刷新数据，所以如果当前查询的是第1页，要清空原有
                            if (pageindex == 1) {
                                $$("#sub_orderList_tab1 .list-block ul").html("");
                            }
                            $$("#sub_orderList_tab1 .list-block ul").append(html);

                        }
                        //current_tab_index 待付款
                        else if (currentIndex == 1) {
                            //因为每次点击tab都会刷新数据，所以如果当前查询的是第1页，要清空原有
                            if (pageindex == 1) {
                                $$("#sub_orderList_tab2 .list-block ul").html("");
                            }
                            $$("#sub_orderList_tab2 .list-block ul").append(html);

                            $$("#sub_orderList_tab2 .list-block ul li.dfk").each(function () {
                                //if ($$(this).hasClass("ycs")) return;
                                var li = $$(this);
                                var span_time = $$(this).find(".order-state");
                                var button_pay = $$(this).find(".button.button-pay");
                                $$(span_time).html("待付款");
                                button_pay.remove();
                                // var orderTime30 = ISS.utils.strToDate($$(span_time).attr("orderTime"));
                                // orderTime30 = orderTime30.setMinutes(orderTime30.getMinutes() + 30);
                                // function timer() {
                                //     var ts = orderTime30 - new Date().getTime(); //计算剩余的毫秒数 
                                //     if (ts <= 0) {
                                //         $$(li).removeClass("dfk").addClass("ycs");
                                //         $$(span_time).html("待付款--已超时");
                                //         button_pay.remove();
                                //         if (timer_Interval != undefined) {
                                //             clearInterval(timer_Interval);
                                //         }
                                //         return;
                                //     }
                                //     var mm = parseInt(ts / 1000 / 60 % 60, 10); //计算剩余的分钟数  
                                //     var ss = parseInt(ts / 1000 % 60, 10); //计算剩余的秒数  
                                //     mm = checkTime(mm);
                                //     ss = checkTime(ss);
                                //     $$(span_time).html("待付款&nbsp;" + mm + ":" + ss);
                                // }
                                // var timer_Interval = setInterval(timer, 1000);
                            })
                        }
                        //current_tab_index 全部
                        else if (currentIndex == 2) {
                            //因为每次点击tab都会刷新数据，所以如果当前查询的是第1页，要清空原有
                            if (pageindex == 1) {
                                $$("#sub_orderList_tab3 .list-block ul").html("");
                            }
                            $$("#sub_orderList_tab3 .list-block ul").append(html);

                            $$("#sub_orderList_tab3 .list-block ul li.dfk").each(function () {
                                //if ($$(this).hasClass("ycs")) return;
                                var li = $$(this);
                                var span_time = $$(this).find(".order-state");
                                var button_pay = $$(this).find(".button.button-pay");
                                $$(span_time).html("待付款");
                                button_pay.remove();
                                // var orderTime30 = ISS.utils.strToDate($$(span_time).attr("orderTime"));
                                // orderTime30 = orderTime30.setMinutes(orderTime30.getMinutes() + 30);
                                // function timer() {
                                //     var ts = orderTime30 - new Date().getTime(); //计算剩余的毫秒数 
                                //     if (ts <= 0) {
                                //         $$(span_time).html("待付款--已超时");
                                //         $$(li).removeClass("dfk").addClass("ycs");
                                //         button_pay.remove();
                                //         if (timer_Interval != undefined) {
                                //             clearInterval(timer_Interval);
                                //         }

                                //         return;
                                //     }
                                //     var mm = parseInt(ts / 1000 / 60 % 60, 10); //计算剩余的分钟数  
                                //     var ss = parseInt(ts / 1000 % 60, 10); //计算剩余的秒数  
                                //     mm = checkTime(mm);
                                //     ss = checkTime(ss);
                                //     $$(span_time).html("待付款&nbsp;" + mm + ":" + ss);
                                // }
                                // var timer_Interval = setInterval(timer, 1000);
                            })
                        }
                    }

                    //tab1综合,无限滚动只加载一次
                    if (!flag_execute) {
                        //只执行一次
                        flag_execute = true;

                        // 加载flag
                        var loading = false;
                        $$('.infinite-scroll').on('infinite', function () {
                            //切换
                            if (!flag_needScroll) {
                                flag_needScroll = true;
                                return;
                            }

                            //查询时,删除滚动后重新绑定pageindex
                            if (!flag_InfiniteScroll) {
                                flag_InfiniteScroll = true;
                                return;
                            }

                            if (true) {
                                // 如果正在加载，则退出
                                if (loading) return;
                                // 设置flag
                                loading = true;
                                // 模拟1s的加载过程
                                setTimeout(function () {
                                    // 重置加载flag
                                    loading = false;
                                    if (current_tabindex == 0) {
                                        index_tab0++;
                                        LoadOrderAll(index_tab0, current_tabindex);
                                    }
                                    else if (current_tabindex == 1) {
                                        index_tab1++;
                                        LoadOrderAll(index_tab1, current_tabindex);
                                    }
                                    else if (current_tabindex == 2) {
                                        index_tab2++;
                                        LoadOrderAll(index_tab2, current_tabindex);
                                    }
                                }, 100);
                            }
                        });
                    }

                    if (current_tabindex == 0 && $$("#sub_orderList_tab1 .list-block ul li").length >= parseInt(data.total)) {
                        // 删除加载提示符
                        $$('.infinite-scroll-preloader1').remove();
                        // 加载完毕，则注销无限加载事件，以防不必要的加载
                        myApp.detachInfiniteScroll($$('.infinite-scroll'));
                    }
                    else if (current_tabindex == 1 && $$("#sub_orderList_tab2 .list-block ul li").length >= parseInt(data.total)) {
                        // 删除加载提示符
                        $$('.infinite-scroll-preloader2').remove();
                        // 加载完毕，则注销无限加载事件，以防不必要的加载
                        myApp.detachInfiniteScroll($$('.infinite-scroll'));
                    }
                    else if (current_tabindex == 2 && $$("#sub_orderList_tab3 .list-block ul li").length >= parseInt(data.total)) {
                        // 删除加载提示符
                        $$('.infinite-scroll-preloader3').remove();
                        // 加载完毕，则注销无限加载事件，以防不必要的加载
                        myApp.detachInfiniteScroll($$('.infinite-scroll'));
                    }
                }
                else {
                    //清空内容
                    if (currentIndex == 0) {
                        $$("#sub_orderList_tab1 .list-block ul").html("");
                    } else if (currentIndex == 1) {
                        $$("#sub_orderList_tab2 .list-block ul").html("");
                    } else if (currentIndex == 2) {
                        $$("#sub_orderList_tab3 .list-block ul").html("");
                    }
                    // 删除加载提示符
                    myApp.detachInfiniteScroll($$('.infinite-scroll'));
                    if (current_tabindex == 0) {
                        $$('.infinite-scroll-preloader1').remove();
                        if ($$("#sub_orderList_tab1 .list-block ul li").length <= 0) {
                            $$("#sub_orderList_tab1 .list-block ul").html(ISS_Element.DIV.noAnswer);
                            $$("#sub_orderList_tab1 .noAnswer").on("click", function () {
                                index_tab0=1;
                                
                                LoadOrderAll(index_tab0, current_tabindex);
                            });
                        }
                    }
                    else if (current_tabindex == 1) {
                        $$('.infinite-scroll-preloader2').remove();
                        if ($$("#sub_orderList_tab2 .list-block ul li").length <= 0) {
                            $$("#sub_orderList_tab2 .list-block ul").html(ISS_Element.DIV.noAnswer);
                            $$("#sub_orderList_tab2 .noAnswer").on("click", function () {
                                index_tab1=1;
                                
                                LoadOrderAll(index_tab1, current_tabindex);
                            });
                        }
                    }
                    else if (current_tabindex == 2) {
                        $$('.infinite-scroll-preloader3').remove();
                        if ($$("#sub_orderList_tab3 .list-block ul li").length <= 0) {
                            $$("#sub_orderList_tab3 .list-block ul").html(ISS_Element.DIV.noAnswer);
                            $$("#sub_orderList_tab3 .noAnswer").on("click", function () {
                                index_tab2=1;
                                
                                LoadOrderAll(index_tab2, current_tabindex);
                            });
                        }
                    }
                }
            },
            error: function (xhr, status) { 
                myApp.hidePreloader();
                myApp.alert("服务器连接失败！");
            }
        });
    }

    //详情页面弹出、样式、按钮事件(待付款、已超时、已使用、已付款、未知)
    //门票
    if (orderType == "1") {
        //标题
        $$("#orderlist_page .center").html("我的门票订单");
        //只要   非待付款   的都是弹出这样的层
        //        $$("#orderlist_page .page-content ul ").on("click", "li:not([class='dfk'])", function () {
        $$("#orderlist_page .page-content ul ").on("click", "li", function () {
            var orderno = $$(this).attr("orderno");
            iss_localStorage.set("yuqing_isfresh", "false");
            mainView.router.loadPage({ url: "../../view-yuqing/elements/ticketBookingDetail.html?OrderNo=" + orderno, reload: false });

            // var orderno = $$(this).attr("orderno");
            // var _content = JSON.stringify({
            //     Code: orderno,
            //     type: 1
            // });
            // myApp.showPreloader();
            // $$.ajax({
            //     url: ISS_Constants.Url.defaulturl + ISS_Constants.serviceName.ORDERS,
            //     data: { "content": _content },
            //     crossDomain: true,
            //     method: "POST",
            //     success: function (data, status) {
            //         try {
            //             data = JSON.parse(data);
            //             if (data && data.status == "0") {
            //                 data.results.getTicketOrderInfo[0].playDate = toDateFormat(data.results.getTicketOrderInfo[0].playDate);

            //                 data.results.orderTime = toDateFormatFull(data.results.orderTime);
            //                 //中间数据模板
            //                 var searchTemplate = $$('#template-ticketorder-detail').html();
            //                 if (searchTemplate) {
            //                     var compiledTemplate = Template7.compile(searchTemplate);
            //                     var html = compiledTemplate(data.results);
            //                     $$(".popup-scenic div.popup-main").html(html);
            //                     if (data.results.orderSTATUS == "2") {
            //                         $$(".popup-scenic .popup-info.btn_fk").show(); //显示付款按钮
            //                     }
            //                     if (data.results.orderSTATUS == "4") {
            //                         $$(".popup-scenic .popup-info.btn_tk").show(); //显示退款按钮
            //                     }
            //                     if (data.results.orderSTATUS == "1" || data.results.orderSTATUS == "2" || data.results.orderSTATUS == "3"
            //                      || data.results.orderSTATUS == "7" || data.results.orderSTATUS == "11") {
            //                         $$(".popup-scenic .popup-info.btn_del").show(); //显示删除按钮
            //                     }
            //                 }
            //                 var visitorInfolist = data.results.getTicketOrderInfo; 
            //                 var visitorhtml = "";
            //                 for (var i = 0; i < visitorInfolist.length; i++) {
            //                     var visitorInfo = visitorInfolist[i].visitorInfos.split(',');
            //                     visitorhtml += "<div class='tourist-info'><h5>旅客" + (i + 1).toString();
            //                     visitorhtml += "</h5><ul><li>旅客姓名：" + visitorInfo[0];
            //                     visitorhtml += "</li><li>身份证号：" + visitorInfo[1];
            //                     visitorhtml += "</li></ul></div>";
            //                 }
            //                 $$(".popup-scenic div.popup-main .visitor").html(visitorhtml);
            //                 myApp.hidePreloader();
            //                 myApp.popup('.popup-scenic');
            //             }
            //             else {
            //                 myApp.hidePreloader();
            //                 myApp.alert('参数错误!');
            //             }
            //         } catch (ex) {
            //             myApp.hidePreloader();
            //         }
            //     },
            //     error: function (xhr, status) {
            //         myApp.hidePreloader();
            //         myApp.alert('参数错误!');
            //     }
            // });
        });
    }
    //酒店
    else if (orderType == "2") {
        //标题
        $$("#orderlist_page .center").html("我的酒店订单");
        //只要   非待付款   的都是弹出这样的层
        //        $$("#orderlist_page .page-content ul ").on("click", "li:not([class='dfk'])", function () {
        $$("#orderlist_page .page-content ul ").on("click", "li", function () {
            var orderno = $$(this).attr("orderno");
            var _content = JSON.stringify({
                Code: orderno,
                type: 1
            });
            myApp.showPreloader();
            $$.ajax({
                url: ISS_Constants.Url.defaulturl + ISS_Constants.serviceName.ORDERS,
                data: { "content": _content },
                crossDomain: true,
                method: "POST",
                success: function (data, status) {
                    try {
                        data = JSON.parse(data);
                        if (data && data.status == "0") {

                            data.results.orderTime = toDateFormatFull(data.results.orderTime);
                            if (data.results.getHotelOrderInfo && data.results.getHotelOrderInfo.length > 0) {
                                data.results.getHotelOrderInfo[0].ARRIVALDATE = toDateFormat(data.results.getHotelOrderInfo[0].ARRIVALDATE);
                                data.results.getHotelOrderInfo[0].FINISHEDDATE = toDateFormat(data.results.getHotelOrderInfo[0].FINISHEDDATE);
                            }
                            //中间数据模板
                            var searchTemplate = $$('#template-hotelorder-detail').html();
                            if (searchTemplate) {
                                var compiledTemplate = Template7.compile(searchTemplate);
                                var html = compiledTemplate(data.results);
                                $$(".popup-hotel div.popup-main").html(html);
                                if (data.results.orderSTATUS == "2") {
                                    $$(".popup-hotel .popup-info.btn_fk").show(); //显示付款按钮
                                }
                                if (data.results.orderSTATUS == "4") {
                                    $$(".popup-hotel .popup-info.btn_tk").show(); //显示退款按钮
                                }
                                if (data.results.orderSTATUS == "1" || data.results.orderSTATUS == "2" || data.results.orderSTATUS == "3"
                                    || data.results.orderSTATUS == "7" || data.results.orderSTATUS == "11") {
                                    $$(".popup-hotel .popup-info.btn_del").show(); //显示删除按钮
                                }
                            }


                            myApp.hidePreloader();
                            myApp.popup('.popup-hotel');
                        }
                        else {
                            myApp.hidePreloader();
                            myApp.alert('参数错误!');
                        }
                    } catch (ex) {
                        myApp.hidePreloader();
                    }
                },
                error: function (xhr, status) {
                    myApp.hidePreloader();
                    myApp.alert('参数错误!');
                }
            });

        });
    }
    //线路
    else if (orderType == "3") {
        //标题
        $$("#orderlist_page .center").html("我的线路订单");
        //只要   非待付款   的都是弹出这样的层
        //        $$("#orderlist_page .page-content ul ").on("click", "li:not([class='dfk'])", function () {
        $$("#orderlist_page .page-content ul ").on("click", "li", function () {
            var orderno = $$(this).attr("orderno");
            var _content = JSON.stringify({
                Code: orderno,
                type: 1
            });
            myApp.showPreloader();
            $$.ajax({
                url: ISS_Constants.Url.defaulturl + ISS_Constants.serviceName.ORDERS,
                data: { "content": _content },
                crossDomain: true,
                method: "POST",
                success: function (data, status) {
                    try {
                        data = JSON.parse(data);
                        if (data && data.status == "0") {

                            data.results.orderTime = toDateFormatFull(data.results.orderTime);
                            //中间数据模板
                            var searchTemplate = $$('#template-line-detail').html();
                            if (searchTemplate) {
                                var compiledTemplate = Template7.compile(searchTemplate);
                                var html = compiledTemplate(data.results);
                                $$(".popup-line div.popup-main").html(html);
                                if (data.results.orderSTATUS == "2") {
                                    $$(".popup-line .popup-info.btn_fk").show(); //显示付款按钮
                                }
                                if (data.results.orderSTATUS == "4") {
                                    $$(".popup-line .popup-info.btn_tk").show(); //显示退款按钮
                                }
                                if (data.results.orderSTATUS == "1" || data.results.orderSTATUS == "2" || data.results.orderSTATUS == "3"
                                    || data.results.orderSTATUS == "7" || data.results.orderSTATUS == "11") {
                                    $$(".popup-line .popup-info.btn_del").show(); //显示删除按钮
                                }
                            }


                            myApp.hidePreloader();
                            myApp.popup('.popup-line');
                        }
                        else {
                            myApp.hidePreloader();
                            myApp.alert('参数错误!');
                        }
                    } catch (ex) {
                        myApp.hidePreloader();
                    }
                },
                error: function (xhr, status) {
                    myApp.hidePreloader();
                    myApp.alert('参数错误!');
                }
            });

        });
    }
    //团购
    else if (orderType == "22") {
        //标题
        $$("#orderlist_page .center").html("我的团购订单");
        //只要   非待付款   的都是弹出这样的层
        //        $$("#orderlist_page .page-content ul ").on("click", "li:not([class='dfk'])", function () {
        $$("#orderlist_page .page-content ul ").on("click", "li", function () {
            var orderno = $$(this).attr("orderno");
            var _content = JSON.stringify({
                Code: orderno,
                type: 1
            });
            myApp.showPreloader();
            $$.ajax({
                url: ISS_Constants.Url.defaulturl + ISS_Constants.serviceName.ORDERS,
                data: { "content": _content },
                crossDomain: true,
                method: "POST",
                success: function (data, status) {
                    try {
                        data = JSON.parse(data);
                        if (data && data.status == "0") {

                            data.results.orderTime = toDateFormatFull(data.results.orderTime);
                            //中间数据模板
                            var searchTemplate = $$('#template-group-detail').html();
                            if (searchTemplate) {
                                var compiledTemplate = Template7.compile(searchTemplate);
                                var html = compiledTemplate(data.results);
                                $$(".popup-group div.popup-main").html(html);
                                if (data.results.orderSTATUS == "2") {
                                    $$(".popup-group .popup-info.btn_fk").show(); //显示付款按钮
                                }
                                if (data.results.orderSTATUS == "4") {
                                    $$(".popup-group .popup-info.btn_tk").show(); //显示退款按钮
                                }
                                if (data.results.orderSTATUS == "1" || data.results.orderSTATUS == "2" || data.results.orderSTATUS == "3"
                                    || data.results.orderSTATUS == "7" || data.results.orderSTATUS == "11") {
                                    $$(".popup-group .popup-info.btn_del").show(); //显示删除按钮
                                }
                            }


                            myApp.hidePreloader();
                            myApp.popup('.popup-group');
                        }
                        else {
                            myApp.hidePreloader();
                            myApp.alert('参数错误!');
                        }
                    } catch (ex) {
                        myApp.hidePreloader();
                    }
                },
                error: function (xhr, status) {
                    myApp.hidePreloader();
                    myApp.alert('参数错误!');
                }
            });

        });
    }

    //付款按钮
    $$("#orderlist_page .popup-scenic .content-block").on("click", ".btn_fk", function () {
        var orderno = $$(this).attr("orderno");
        var ordername = $$(this).attr("ordername");
        iss_localStorage.set("yuqing_isfresh", "false");
        mainView.router.loadPage({ url: "../../view-yuqing/elements/ticketBookingDetail.html?OrderNo=" + orderno, reload: false });
    })
    $$("#orderlist_page .popup-hotel .content-block").on("click", ".btn_fk", function () {
        var orderno = $$(this).attr("orderno");
        var ordername = $$(this).attr("ordername");
        mainView.router.loadPage({ url: "../../view/booking/hotelPay.html?OrderNo=" + orderno + "&orderName=" + ordername, reload: false });
    })
    $$("#orderlist_page .popup-line .content-block").on("click", ".btn_fk", function () {
        var orderno = $$(this).attr("orderno");
        var ordername = $$(this).attr("ordername");
        mainView.router.loadPage({ url: "../../view/booking/linePay.html?OrderNo=" + orderno + "&orderName=" + ordername, reload: false });
    })
    $$("#orderlist_page .popup-group .content-block").on("click", ".btn_fk", function () {
        var orderno = $$(this).attr("orderno");
        var ordername = $$(this).attr("ordername");
        mainView.router.loadPage({ url: "../../view/booking/groupPay.html?OrderNo=" + orderno + "&orderName=" + ordername, reload: false });
    })

    //申请退款按钮
    $$("#orderlist_page .popup .content-block").on("click", ".btn_tk", function () {
        var condition = JSON.stringify({
            orderNo: $$(this).attr("orderno"),
            orderName: $$(this).attr("ordername"),
            refund_amount: $$(this).attr("onlinePay"),
            actionStatus: 1
        });
        myApp.alert('确定申请退款？', function () {
            var url = ISS_Constants.Url.const_weixin_applyrefund;
            $$.ajax({
                url: url,
                crossDomain: true,
                data: { conditionParm: condition },
                method: "POST",
                success: function (data, status) {
                    data = JSON.parse(data);
                    //关闭模态窗
                    myApp.hidePreloader();
                    //关闭详情popup窗口
                    if (orderType == "0") {
                        myApp.closeModal('.popup-scenic');
                    } else if (orderType == "1") {
                        myApp.closeModal('.popup-hotel');
                    } else if (orderType == "2") {
                        myApp.closeModal('.popup-line');
                    } else if (orderType == "22") {
                        myApp.closeModal('.popup-group');
                    }
                    //提示
                    if (data.success == true && data.datas == "OK") {
                        //提示成功
                        myApp.alert('申请退款成功', function () {
                            //重新加载主界面
                            LoadOrderAll(1, 2);
                            myApp.showTab("#sub_orderList_tab3");
                        });
                    } else {
                        //提示失败
                        myApp.alert('申请退款失败！', function () {
                            //重新加载主界面
                            LoadOrderAll(1, 2);
                            myApp.showTab("#sub_orderList_tab3");
                        });
                    };
                },
                error: function (xhr, status) {
                    myApp.hidePreloader();
                    myApp.alert('参数错误!');
                }
            });
        });
    })

    //删除按钮
    $$("#orderlist_page .popup .content-block").on("click", ".btn_del", function () {
        //condition放到myApp外面，否者this对象是弹出层
        var _condition = JSON.stringify({
            type: 113, //接口类型
            orderOperationEntity: {
                OrderNo: $$(this).attr("orderno"), //订单号
                OrderType: $$(this).attr("orderType"), //订单类型 0：景区 1：酒店 2：线路
                UserID: iss_localStorage.get("yuqing_appUserId")//用户ID
            }
        });
        myApp.alert('确定删除订单？', function () {
            var url = ISS_Constants.Url.defaulturl + ISS_Constants.serviceName.DELORDER;
            $$.ajax({
                url: url,
                crossDomain: true,
                data: { content: _condition },
                method: "POST",
                success: function (data, status) {
                    data = JSON.parse(data);
                    //关闭模态窗
                    myApp.hidePreloader();
                    //关闭详情popup窗口
                    if (orderType == "0") {
                        myApp.closeModal('.popup-scenic');
                    } else if (orderType == "1") {
                        myApp.closeModal('.popup-hotel');
                    } else if (orderType == "2") {
                        myApp.closeModal('.popup-line');
                    } else if (orderType == "22") {
                        myApp.closeModal('.popup-group');
                    }
                    //提示
                    if (data.success == true && data.datas == "OK") {
                        //提示成功
                        myApp.alert('删除成功', function () {
                            //重新加载主界面
                            LoadOrderAll(1, 2);
                            myApp.showTab("#sub_orderList_tab3");
                        });
                    } else {
                        //提示失败
                        myApp.alert('删除失败！', function () {
                            //重新加载主界面
                            LoadOrderAll(1, 2);
                            myApp.showTab("#sub_orderList_tab3");
                        });
                    };
                },
                error: function (xhr, status) {
                    myApp.hidePreloader();
                    myApp.alert('参数错误!');
                }
            });
        });
    })

    //格式化数据
    function formatData(result) {
        result.statusName = ""; //状态中文
        result.statusClass = ""; //状态前台css类
        var STATUS = result.orderSTATUS;
        switch (STATUS) {
            case 1:
                result.statusName = "待确认";
                break;
            case 2:
                {
                    result.statusName = "待付款";
                    var orderTime30 = ISS.utils.strToDate(result.orderTime);
                    orderTime30 = orderTime30.setMinutes(orderTime30.getMinutes() + 30);
                    if ((orderTime30 - new Date().getTime()) > 0) {
                        //未超时数据
                        result.statusClass = "dfk";
                    }
                    else {
                        result.statusClass = "ycs";
                    }
                }
                break;
            case 3:
                result.statusName = "已取消";
                break;
            case 4:
                result.statusName = "已支付";
                result.statusClass = "yfk";
                break;
            case 5:
                result.statusName = "出票中";
                break;
            case 6:
                result.statusName = "未消费";
                break;
            case 7:
                result.statusName = "已消费";
                result.statusClass = "used";
                break;
            case 8:
                result.statusName = "退款申请中";
                result.statusClass = "sqtk";
                break;
            case 9:
                result.statusName = "退款拒绝";
                break;
            case 10:
                result.statusName = "退款中";
                break;
            case 11:
                result.statusName = "已退款";
                break;
            case 12:
                result.statusName = "预支付成功";
                break;
            case 13:
                result.statusName = "已入住";
                break;
            case 14:
                result.statusName = "提前退房申请";
                break;
            case 15:
                result.statusName = "提前退房通过";
                break;
            case 16:
                result.statusName = "提前退房拒绝";
                break;
            case 17:
                result.statusName == "退货申请中";
                break;
            case 18:
                result.statusName = "已发货";
                break;
            case 19:
                result.statusName = "已签收";
                break;
            case 20:
                result.statusName = "退货同意";
                break;
            case 21:
                result.statusName = "退货中";
                break;
            case 22:
                result.statusName = "退款审核中";
                break;
            case 23:
                result.statusName = "退货拒绝";
                break;
            case 24:
                result.statusName = "财务退款中";
                break;
            case 25:
                result.statusName = "提前退房财务退款中";
                break;
            default:
                result.statusName = "完成";
        }
        return result;
    }

});

//订单列表
var contactsCallback_orderList = myApp.onPageInit('orderlist', function (page) {
    //获取页面参数 类型 0:景区,1:酒店,2：线路,22:团购
    var orderType = ISS.utils.getParameter("orderType");
    if (page != undefined) {
        orderType = page.query.orderType;
    }
    // 全局变量
    var _userID = iss_localStorage.get("yuqing_appUserId");

    //点击第一次页面执行
    var flag_order_tab1 = true;
    //当前tab标签，0：已付款 1：待付款 2：全部
    // var current_tabindex = 0;
    //定义每页的页数
    var size = 10;
    //每个tab的当前页
    var index_tab0 = 1;
    var index_tab1 = 1;
    var index_tab2 = 1;
    //删除滚动后重新添加滚动
    var flag_InfiniteScroll = true;
    //是否需要滚动加载
    var flag_needScroll = true;
    //滚动事件只执行一次
    var flag_execute = false;
    //第一次加载显示index_tab1，已付款的
    if (flag_order_tab1 == true) {
        LoadOrderAll(index_tab0, current_tabindex);
        flag_order_tab1 = false;
    }

    //订单类型切换
    $$(".sub_buttons_row a").click(function () {
        $$('.infinite-scroll').scrollTop(0);
        current_tabindex = $$(this).index();
        //加载无限滚动事件
        myApp.attachInfiniteScroll($$('.infinite-scroll'));

        //        if ($$(this).index() == 0 && $$("#sub_orderList_tab1 ul").children("li").length == 0) {
        //            LoadOrderAll(index_tab0, current_tabindex);
        //        }
        //        else if ($$(this).index() == 1 && $$("#sub_orderList_tab2 ul").children("li").length == 0) {
        //            LoadOrderAll(index_tab1, current_tabindex);
        //        }
        //        else if ($$(this).index() == 2 && $$("#sub_orderList_tab3 ul").children("li").length == 0) {
        //            LoadOrderAll(index_tab2, current_tabindex);
        //        }
        //modify by changlishuang 2016-08-12 只要切换table数据不为空，也重新加载数据
        if ($$(this).index() == 0) {
            index_tab0 = 1;
            LoadOrderAll(index_tab0, current_tabindex);
        }
        else if ($$(this).index() == 1) {
            index_tab1 = 1;
            LoadOrderAll(index_tab1, current_tabindex);
        }
        else if ($$(this).index() == 2) {
            index_tab2 = 1;
            LoadOrderAll(index_tab2, current_tabindex);
        }
    });

    //加载数据
    function LoadOrderAll(pageindex, currentIndex) {
        // 检索条件
        var v_search = [];
        //类型: 0:景区,1:酒店,2：线路,22:团购

        v_search.push({
            SearchField: "OrderType",
            ListSearchValue: [
                {
                    ItemValue: orderType
                }
            ]
        });


        //来源
        v_search.push({
            SearchField: "SourceType",
            ListSearchValue: [
                {
                    ItemValue: "2"
                }
            ]
        });
        //用户
        v_search.push({
            SearchField: "UserID",
            ListSearchValue: [{
                ItemValue: _userID
            }]
        });
        //订单状态标签页，2是全部，不需要加条件
        if (currentIndex == 0) {
            //状态
            v_search.push({
                SearchField: "OrderStatus",
                ListSearchValue: [
                    {
                        ItemValue: 4//已支付
                    }
                ]
            });
        }
        else if (currentIndex == 1) {
            v_search.push({
                SearchField: "OrderStatus",
                ListSearchValue: [
                    {
                        ItemValue: 2//待付款
                    }
                ]
            });
        }

        // 排序
        var v_order = [];
        //事件
        var opt = {
            OrderField: "orderTime",
            OrderType: "desc"
        };
        v_order.push(opt);

        //JSON
        var OrderListContent = JSON.stringify({
            type: 0,
            conditionParams: {
                "Page": { "PageSize": size, "PageIndex": pageindex },
                Search: v_search,
                Order: v_order
            }

        });

        myApp.showPreloader();
        $$.ajax({
            url: ISS_Constants.Url.defaulturl + ISS_Constants.serviceName.ORDERS,
            data: { content: OrderListContent },
            dataType: "jsonp",
            method: "POST",
            success: function (data, status) {
                myApp.hidePreloader();
                data = JSON.parse(data);
                if (data && data.results && data.results.length > 0) {
                    //循环每一个订单,处理数据
                    for (var i = 0; i < data.results.length; i++) {
                        //图片处理
                        if (data.results[i].orderPhoto == null || data.results[i].orderPhoto == "") {
                            data.results[i].orderPhoto = NoPicture();
                        };
                        //订单状态，数字转换汉字描述
                        data.results[i] = formatData(data.results[i]);
                        //获取订单orderNumber，订单对应产品数量
                        if (data.results[i].getHotelOrderInfo.length > 0) {
                            data.results[i].orderNumber = data.results[i].getHotelOrderInfo[0].orderNumber;
                        }
                        else if (data.results[i].getLineOrderInfo.length > 0) {
                            data.results[i].orderNumber = data.results[i].getLineOrderInfo[0].orderNumber;
                        }
                        else if (data.results[i].getTicketOrderInfo.length > 0) {
                            data.results[i].orderNumber = data.results[i].getTicketOrderInfo.length;//data.results[i].getTicketOrderInfo[0].orderNumber;
                        }
                        else if (data.results[i].getGroupOrder.length > 0) {
                            data.results[i].orderNumber = data.results[i].getGroupOrder[0].orderNo
                        }
                        //修改酒店订单，修改每天的房间的开始结束日期格式
                        for (var j = 0; j < data.results[i].getHotelOrderInfo.length; j++) {
                            data.results[i].getHotelOrderInfo[j].ARRIVALDATE = toDateFormat(data.results[i].getHotelOrderInfo[j].ARRIVALDATE);
                            data.results[i].getHotelOrderInfo[j].FINISHEDDATE = toDateFormat(data.results[i].getHotelOrderInfo[j].FINISHEDDATE);
                        }
                        //修改门票订单，修改游玩时间的开始结束日期格式
                        for (var j = 0; j < data.results[i].getTicketOrderInfo.length; j++) {
                            data.results[i].getTicketOrderInfo[j].playDate = toDateFormat(data.results[i].getTicketOrderInfo[j].playDate);
                        }
                        for (var j = 0; j < data.results[i].getGroupOrder.length; j++) {
                            data.results[i].getGroupOrder[j].createDate = toDateFormat(data.results[i].getGroupOrder[j].createDate);
                            data.results[i].getGroupOrder[j].toDay = toDateFormat(data.results[i].getGroupOrder[j].toDay);
                        }
                    }
                    //根据订单类型，获取模板页
                    var searchTemplate;
                    if (orderType == "0") {
                        searchTemplate = $$('#template-orderList-ticket').html();
                    }
                    else if (orderType == "1") {
                        searchTemplate = $$('#template-orderList-hotel').html();
                    }
                    //这里应该是线路，只是现在线路没有做，先调用门票的
                    else if (orderType == "2") {
                        searchTemplate = $$('#template-orderList-line').html();
                    }
                    else if (orderType == "22") {
                        searchTemplate = $$('#template-orderList-Group').html();
                    }

                    if (searchTemplate) {
                        var compiledTemplate = Template7.compile(searchTemplate);
                        var html = compiledTemplate(data);
                        //current_tab_index 已付款
                        if (currentIndex == 0) {
                            //因为每次点击tab都会刷新数据，所以如果当前查询的是第1页，要清空原有
                            if (pageindex == 1) {
                                $$("#sub_orderList_tab1 .list-block ul").html("");
                            }
                            $$("#sub_orderList_tab1 .list-block ul").append(html);

                        }
                        //current_tab_index 待付款
                        else if (currentIndex == 1) {
                            //因为每次点击tab都会刷新数据，所以如果当前查询的是第1页，要清空原有
                            if (pageindex == 1) {
                                $$("#sub_orderList_tab2 .list-block ul").html("");
                            }
                            $$("#sub_orderList_tab2 .list-block ul").append(html);

                            $$("#sub_orderList_tab2 .list-block ul li.dfk").each(function () {
                                //if ($$(this).hasClass("ycs")) return;
                                var li = $$(this);
                                var span_time = $$(this).find(".order-state");
                                var button_pay = $$(this).find(".button.button-pay");
                                $$(span_time).html("待付款");
                                button_pay.remove();
                                // var orderTime30 = ISS.utils.strToDate($$(span_time).attr("orderTime"));
                                // orderTime30 = orderTime30.setMinutes(orderTime30.getMinutes() + 30);
                                // function timer() {
                                //     var ts = orderTime30 - new Date().getTime(); //计算剩余的毫秒数 
                                //     if (ts <= 0) {
                                //         $$(li).removeClass("dfk").addClass("ycs");
                                //         $$(span_time).html("待付款--已超时");
                                //         button_pay.remove();
                                //         if (timer_Interval != undefined) {
                                //             clearInterval(timer_Interval);
                                //         }
                                //         return;
                                //     }
                                //     var mm = parseInt(ts / 1000 / 60 % 60, 10); //计算剩余的分钟数  
                                //     var ss = parseInt(ts / 1000 % 60, 10); //计算剩余的秒数  
                                //     mm = checkTime(mm);
                                //     ss = checkTime(ss);
                                //     $$(span_time).html("待付款&nbsp;" + mm + ":" + ss);
                                // }
                                // var timer_Interval = setInterval(timer, 1000);
                            })
                        }
                        //current_tab_index 全部
                        else if (currentIndex == 2) {
                            //因为每次点击tab都会刷新数据，所以如果当前查询的是第1页，要清空原有
                            if (pageindex == 1) {
                                $$("#sub_orderList_tab3 .list-block ul").html("");
                            }
                            $$("#sub_orderList_tab3 .list-block ul").append(html);

                            $$("#sub_orderList_tab3 .list-block ul li.dfk").each(function () {
                                //if ($$(this).hasClass("ycs")) return;
                                var li = $$(this);
                                var span_time = $$(this).find(".order-state");
                                var button_pay = $$(this).find(".button.button-pay");
                                $$(span_time).html("待付款");
                                button_pay.remove();
                                // var orderTime30 = ISS.utils.strToDate($$(span_time).attr("orderTime"));
                                // orderTime30 = orderTime30.setMinutes(orderTime30.getMinutes() + 30);
                                // function timer() {
                                //     var ts = orderTime30 - new Date().getTime(); //计算剩余的毫秒数 
                                //     if (ts <= 0) {
                                //         $$(span_time).html("待付款--已超时");
                                //         $$(li).removeClass("dfk").addClass("ycs");
                                //         button_pay.remove();
                                //         if (timer_Interval != undefined) {
                                //             clearInterval(timer_Interval);
                                //         }

                                //         return;
                                //     }
                                //     var mm = parseInt(ts / 1000 / 60 % 60, 10); //计算剩余的分钟数  
                                //     var ss = parseInt(ts / 1000 % 60, 10); //计算剩余的秒数  
                                //     mm = checkTime(mm);
                                //     ss = checkTime(ss);
                                //     $$(span_time).html("待付款&nbsp;" + mm + ":" + ss);
                                // }
                                // var timer_Interval = setInterval(timer, 1000);
                            })
                        }
                    }

                    //tab1综合,无限滚动只加载一次
                    if (!flag_execute) {
                        //只执行一次
                        flag_execute = true;

                        // 加载flag
                        var loading = false;
                        $$('.infinite-scroll').on('infinite', function () {
                            //切换
                            if (!flag_needScroll) {
                                flag_needScroll = true;
                                return;
                            }

                            //查询时,删除滚动后重新绑定pageindex
                            if (!flag_InfiniteScroll) {
                                flag_InfiniteScroll = true;
                                return;
                            }

                            if (true) {
                                // 如果正在加载，则退出
                                if (loading) return;
                                // 设置flag
                                loading = true;
                                // 模拟1s的加载过程
                                setTimeout(function () {
                                    // 重置加载flag
                                    loading = false;
                                    if (current_tabindex == 0) {
                                        index_tab0++;
                                        LoadOrderAll(index_tab0, current_tabindex);
                                    }
                                    else if (current_tabindex == 1) {
                                        index_tab1++;
                                        LoadOrderAll(index_tab1, current_tabindex);
                                    }
                                    else if (current_tabindex == 2) {
                                        index_tab2++;
                                        LoadOrderAll(index_tab2, current_tabindex);
                                    }
                                }, 100);
                            }
                        });
                    }

                    if (current_tabindex == 0 && $$("#sub_orderList_tab1 .list-block ul li").length >= parseInt(data.total)) {
                        // 删除加载提示符
                        $$('.infinite-scroll-preloader1').remove();
                        // 加载完毕，则注销无限加载事件，以防不必要的加载
                        myApp.detachInfiniteScroll($$('.infinite-scroll'));
                    }
                    else if (current_tabindex == 1 && $$("#sub_orderList_tab2 .list-block ul li").length >= parseInt(data.total)) {
                        // 删除加载提示符
                        $$('.infinite-scroll-preloader2').remove();
                        // 加载完毕，则注销无限加载事件，以防不必要的加载
                        myApp.detachInfiniteScroll($$('.infinite-scroll'));
                    }
                    else if (current_tabindex == 2 && $$("#sub_orderList_tab3 .list-block ul li").length >= parseInt(data.total)) {
                        // 删除加载提示符
                        $$('.infinite-scroll-preloader3').remove();
                        // 加载完毕，则注销无限加载事件，以防不必要的加载
                        myApp.detachInfiniteScroll($$('.infinite-scroll'));
                    }
                }
                else {
                    //清空内容
                    if (currentIndex == 0) {
                        $$("#sub_orderList_tab1 .list-block ul").html("");
                    } else if (currentIndex == 1) {
                        $$("#sub_orderList_tab2 .list-block ul").html("");
                    } else if (currentIndex == 2) {
                        $$("#sub_orderList_tab3 .list-block ul").html("");
                    }
                    // 删除加载提示符
                    myApp.detachInfiniteScroll($$('.infinite-scroll'));
                    if (current_tabindex == 0) {
                        $$('.infinite-scroll-preloader1').remove();
                        if ($$("#sub_orderList_tab1 .list-block ul li").length <= 0) {
                            $$("#sub_orderList_tab1 .list-block ul").html(ISS_Element.DIV.noAnswer);
                            $$("#sub_orderList_tab1 .noAnswer").on("click", function () {
                                index_tab0=1;
                                
                                LoadOrderAll(index_tab0, current_tabindex);
                            });
                        }
                    }
                    else if (current_tabindex == 1) {
                        $$('.infinite-scroll-preloader2').remove();
                        if ($$("#sub_orderList_tab2 .list-block ul li").length <= 0) {
                            $$("#sub_orderList_tab2 .list-block ul").html(ISS_Element.DIV.noAnswer);
                            $$("#sub_orderList_tab2 .noAnswer").on("click", function () {
                                index_tab1=1;
                                
                                LoadOrderAll(index_tab1, current_tabindex);
                            });
                        }
                    }
                    else if (current_tabindex == 2) {
                        $$('.infinite-scroll-preloader3').remove();
                        if ($$("#sub_orderList_tab3 .list-block ul li").length <= 0) {
                            $$("#sub_orderList_tab3 .list-block ul").html(ISS_Element.DIV.noAnswer);
                            $$("#sub_orderList_tab3 .noAnswer").on("click", function () {
                                index_tab2=1;
                                
                                LoadOrderAll(index_tab2, current_tabindex);
                            });
                        }
                    }
                }
            },
            error: function (xhr, status) { 
                myApp.hidePreloader();
                myApp.alert("服务器连接失败！");
            }
        });
    }

    //详情页面弹出、样式、按钮事件(待付款、已超时、已使用、已付款、未知)
    //门票
    if (orderType == "1") {
        //标题
        $$("#orderlist_page .center").html("我的门票订单");
        //只要   非待付款   的都是弹出这样的层
        //        $$("#orderlist_page .page-content ul ").on("click", "li:not([class='dfk'])", function () {
        $$("#orderlist_page .page-content ul ").on("click", "li", function () {
            var orderno = $$(this).attr("orderno");
            iss_localStorage.set("yuqing_isfresh", "false");
            mainView.router.loadPage({ url: "../../view-yuqing/elements/ticketBookingDetail.html?OrderNo=" + orderno, reload: false });

            // var orderno = $$(this).attr("orderno");
            // var _content = JSON.stringify({
            //     Code: orderno,
            //     type: 1
            // });
            // myApp.showPreloader();
            // $$.ajax({
            //     url: ISS_Constants.Url.defaulturl + ISS_Constants.serviceName.ORDERS,
            //     data: { "content": _content },
            //     crossDomain: true,
            //     method: "POST",
            //     success: function (data, status) {
            //         try {
            //             data = JSON.parse(data);
            //             if (data && data.status == "0") {
            //                 data.results.getTicketOrderInfo[0].playDate = toDateFormat(data.results.getTicketOrderInfo[0].playDate);

            //                 data.results.orderTime = toDateFormatFull(data.results.orderTime);
            //                 //中间数据模板
            //                 var searchTemplate = $$('#template-ticketorder-detail').html();
            //                 if (searchTemplate) {
            //                     var compiledTemplate = Template7.compile(searchTemplate);
            //                     var html = compiledTemplate(data.results);
            //                     $$(".popup-scenic div.popup-main").html(html);
            //                     if (data.results.orderSTATUS == "2") {
            //                         $$(".popup-scenic .popup-info.btn_fk").show(); //显示付款按钮
            //                     }
            //                     if (data.results.orderSTATUS == "4") {
            //                         $$(".popup-scenic .popup-info.btn_tk").show(); //显示退款按钮
            //                     }
            //                     if (data.results.orderSTATUS == "1" || data.results.orderSTATUS == "2" || data.results.orderSTATUS == "3"
            //                      || data.results.orderSTATUS == "7" || data.results.orderSTATUS == "11") {
            //                         $$(".popup-scenic .popup-info.btn_del").show(); //显示删除按钮
            //                     }
            //                 }
            //                 var visitorInfolist = data.results.getTicketOrderInfo; 
            //                 var visitorhtml = "";
            //                 for (var i = 0; i < visitorInfolist.length; i++) {
            //                     var visitorInfo = visitorInfolist[i].visitorInfos.split(',');
            //                     visitorhtml += "<div class='tourist-info'><h5>旅客" + (i + 1).toString();
            //                     visitorhtml += "</h5><ul><li>旅客姓名：" + visitorInfo[0];
            //                     visitorhtml += "</li><li>身份证号：" + visitorInfo[1];
            //                     visitorhtml += "</li></ul></div>";
            //                 }
            //                 $$(".popup-scenic div.popup-main .visitor").html(visitorhtml);
            //                 myApp.hidePreloader();
            //                 myApp.popup('.popup-scenic');
            //             }
            //             else {
            //                 myApp.hidePreloader();
            //                 myApp.alert('参数错误!');
            //             }
            //         } catch (ex) {
            //             myApp.hidePreloader();
            //         }
            //     },
            //     error: function (xhr, status) {
            //         myApp.hidePreloader();
            //         myApp.alert('参数错误!');
            //     }
            // });
        });
    }
    //酒店
    else if (orderType == "2") {
        //标题
        $$("#orderlist_page .center").html("我的酒店订单");
        //只要   非待付款   的都是弹出这样的层
        //        $$("#orderlist_page .page-content ul ").on("click", "li:not([class='dfk'])", function () {
        $$("#orderlist_page .page-content ul ").on("click", "li", function () {
            var orderno = $$(this).attr("orderno");
            var _content = JSON.stringify({
                Code: orderno,
                type: 1
            });
            myApp.showPreloader();
            $$.ajax({
                url: ISS_Constants.Url.defaulturl + ISS_Constants.serviceName.ORDERS,
                data: { "content": _content },
                crossDomain: true,
                method: "POST",
                success: function (data, status) {
                    try {
                        data = JSON.parse(data);
                        if (data && data.status == "0") {

                            data.results.orderTime = toDateFormatFull(data.results.orderTime);
                            if (data.results.getHotelOrderInfo && data.results.getHotelOrderInfo.length > 0) {
                                data.results.getHotelOrderInfo[0].ARRIVALDATE = toDateFormat(data.results.getHotelOrderInfo[0].ARRIVALDATE);
                                data.results.getHotelOrderInfo[0].FINISHEDDATE = toDateFormat(data.results.getHotelOrderInfo[0].FINISHEDDATE);
                            }
                            //中间数据模板
                            var searchTemplate = $$('#template-hotelorder-detail').html();
                            if (searchTemplate) {
                                var compiledTemplate = Template7.compile(searchTemplate);
                                var html = compiledTemplate(data.results);
                                $$(".popup-hotel div.popup-main").html(html);
                                if (data.results.orderSTATUS == "2") {
                                    $$(".popup-hotel .popup-info.btn_fk").show(); //显示付款按钮
                                }
                                if (data.results.orderSTATUS == "4") {
                                    $$(".popup-hotel .popup-info.btn_tk").show(); //显示退款按钮
                                }
                                if (data.results.orderSTATUS == "1" || data.results.orderSTATUS == "2" || data.results.orderSTATUS == "3"
                                    || data.results.orderSTATUS == "7" || data.results.orderSTATUS == "11") {
                                    $$(".popup-hotel .popup-info.btn_del").show(); //显示删除按钮
                                }
                            }


                            myApp.hidePreloader();
                            myApp.popup('.popup-hotel');
                        }
                        else {
                            myApp.hidePreloader();
                            myApp.alert('参数错误!');
                        }
                    } catch (ex) {
                        myApp.hidePreloader();
                    }
                },
                error: function (xhr, status) {
                    myApp.hidePreloader();
                    myApp.alert('参数错误!');
                }
            });

        });
    }
    //线路
    else if (orderType == "3") {
        //标题
        $$("#orderlist_page .center").html("我的线路订单");
        //只要   非待付款   的都是弹出这样的层
        //        $$("#orderlist_page .page-content ul ").on("click", "li:not([class='dfk'])", function () {
        $$("#orderlist_page .page-content ul ").on("click", "li", function () {
            var orderno = $$(this).attr("orderno");
            var _content = JSON.stringify({
                Code: orderno,
                type: 1
            });
            myApp.showPreloader();
            $$.ajax({
                url: ISS_Constants.Url.defaulturl + ISS_Constants.serviceName.ORDERS,
                data: { "content": _content },
                crossDomain: true,
                method: "POST",
                success: function (data, status) {
                    try {
                        data = JSON.parse(data);
                        if (data && data.status == "0") {

                            data.results.orderTime = toDateFormatFull(data.results.orderTime);
                            //中间数据模板
                            var searchTemplate = $$('#template-line-detail').html();
                            if (searchTemplate) {
                                var compiledTemplate = Template7.compile(searchTemplate);
                                var html = compiledTemplate(data.results);
                                $$(".popup-line div.popup-main").html(html);
                                if (data.results.orderSTATUS == "2") {
                                    $$(".popup-line .popup-info.btn_fk").show(); //显示付款按钮
                                }
                                if (data.results.orderSTATUS == "4") {
                                    $$(".popup-line .popup-info.btn_tk").show(); //显示退款按钮
                                }
                                if (data.results.orderSTATUS == "1" || data.results.orderSTATUS == "2" || data.results.orderSTATUS == "3"
                                    || data.results.orderSTATUS == "7" || data.results.orderSTATUS == "11") {
                                    $$(".popup-line .popup-info.btn_del").show(); //显示删除按钮
                                }
                            }


                            myApp.hidePreloader();
                            myApp.popup('.popup-line');
                        }
                        else {
                            myApp.hidePreloader();
                            myApp.alert('参数错误!');
                        }
                    } catch (ex) {
                        myApp.hidePreloader();
                    }
                },
                error: function (xhr, status) {
                    myApp.hidePreloader();
                    myApp.alert('参数错误!');
                }
            });

        });
    }
    //团购
    else if (orderType == "22") {
        //标题
        $$("#orderlist_page .center").html("我的团购订单");
        //只要   非待付款   的都是弹出这样的层
        //        $$("#orderlist_page .page-content ul ").on("click", "li:not([class='dfk'])", function () {
        $$("#orderlist_page .page-content ul ").on("click", "li", function () {
            var orderno = $$(this).attr("orderno");
            var _content = JSON.stringify({
                Code: orderno,
                type: 1
            });
            myApp.showPreloader();
            $$.ajax({
                url: ISS_Constants.Url.defaulturl + ISS_Constants.serviceName.ORDERS,
                data: { "content": _content },
                crossDomain: true,
                method: "POST",
                success: function (data, status) {
                    try {
                        data = JSON.parse(data);
                        if (data && data.status == "0") {

                            data.results.orderTime = toDateFormatFull(data.results.orderTime);
                            //中间数据模板
                            var searchTemplate = $$('#template-group-detail').html();
                            if (searchTemplate) {
                                var compiledTemplate = Template7.compile(searchTemplate);
                                var html = compiledTemplate(data.results);
                                $$(".popup-group div.popup-main").html(html);
                                if (data.results.orderSTATUS == "2") {
                                    $$(".popup-group .popup-info.btn_fk").show(); //显示付款按钮
                                }
                                if (data.results.orderSTATUS == "4") {
                                    $$(".popup-group .popup-info.btn_tk").show(); //显示退款按钮
                                }
                                if (data.results.orderSTATUS == "1" || data.results.orderSTATUS == "2" || data.results.orderSTATUS == "3"
                                    || data.results.orderSTATUS == "7" || data.results.orderSTATUS == "11") {
                                    $$(".popup-group .popup-info.btn_del").show(); //显示删除按钮
                                }
                            }


                            myApp.hidePreloader();
                            myApp.popup('.popup-group');
                        }
                        else {
                            myApp.hidePreloader();
                            myApp.alert('参数错误!');
                        }
                    } catch (ex) {
                        myApp.hidePreloader();
                    }
                },
                error: function (xhr, status) {
                    myApp.hidePreloader();
                    myApp.alert('参数错误!');
                }
            });

        });
    }

    //付款按钮
    $$("#orderlist_page .popup-scenic .content-block").on("click", ".btn_fk", function () {
        var orderno = $$(this).attr("orderno");
        var ordername = $$(this).attr("ordername");
        iss_localStorage.set("yuqing_isfresh", "false");
        mainView.router.loadPage({ url: "../../view-yuqing/elements/ticketBookingDetail.html?OrderNo=" + orderno, reload: false });
    })
    $$("#orderlist_page .popup-hotel .content-block").on("click", ".btn_fk", function () {
        var orderno = $$(this).attr("orderno");
        var ordername = $$(this).attr("ordername");
        mainView.router.loadPage({ url: "../../view/booking/hotelPay.html?OrderNo=" + orderno + "&orderName=" + ordername, reload: false });
    })
    $$("#orderlist_page .popup-line .content-block").on("click", ".btn_fk", function () {
        var orderno = $$(this).attr("orderno");
        var ordername = $$(this).attr("ordername");
        mainView.router.loadPage({ url: "../../view/booking/linePay.html?OrderNo=" + orderno + "&orderName=" + ordername, reload: false });
    })
    $$("#orderlist_page .popup-group .content-block").on("click", ".btn_fk", function () {
        var orderno = $$(this).attr("orderno");
        var ordername = $$(this).attr("ordername");
        mainView.router.loadPage({ url: "../../view/booking/groupPay.html?OrderNo=" + orderno + "&orderName=" + ordername, reload: false });
    })

    //申请退款按钮
    $$("#orderlist_page .popup .content-block").on("click", ".btn_tk", function () {
        var condition = JSON.stringify({
            orderNo: $$(this).attr("orderno"),
            orderName: $$(this).attr("ordername"),
            refund_amount: $$(this).attr("onlinePay"),
            actionStatus: 1
        });
        myApp.alert('确定申请退款？', function () {
            var url = ISS_Constants.Url.const_weixin_applyrefund;
            $$.ajax({
                url: url,
                crossDomain: true,
                data: { conditionParm: condition },
                method: "POST",
                success: function (data, status) {
                    data = JSON.parse(data);
                    //关闭模态窗
                    myApp.hidePreloader();
                    //关闭详情popup窗口
                    if (orderType == "0") {
                        myApp.closeModal('.popup-scenic');
                    } else if (orderType == "1") {
                        myApp.closeModal('.popup-hotel');
                    } else if (orderType == "2") {
                        myApp.closeModal('.popup-line');
                    } else if (orderType == "22") {
                        myApp.closeModal('.popup-group');
                    }
                    //提示
                    if (data.success == true && data.datas == "OK") {
                        //提示成功
                        myApp.alert('申请退款成功', function () {
                            //重新加载主界面
                            LoadOrderAll(1, 2);
                            myApp.showTab("#sub_orderList_tab3");
                        });
                    } else {
                        //提示失败
                        myApp.alert('申请退款失败！', function () {
                            //重新加载主界面
                            LoadOrderAll(1, 2);
                            myApp.showTab("#sub_orderList_tab3");
                        });
                    };
                },
                error: function (xhr, status) {
                    myApp.hidePreloader();
                    myApp.alert('参数错误!');
                }
            });
        });
    })

    //删除按钮
    $$("#orderlist_page .popup .content-block").on("click", ".btn_del", function () {
        //condition放到myApp外面，否者this对象是弹出层
        var _condition = JSON.stringify({
            type: 113, //接口类型
            orderOperationEntity: {
                OrderNo: $$(this).attr("orderno"), //订单号
                OrderType: $$(this).attr("orderType"), //订单类型 0：景区 1：酒店 2：线路
                UserID: iss_localStorage.get("yuqing_appUserId")//用户ID
            }
        });
        myApp.alert('确定删除订单？', function () {
            var url = ISS_Constants.Url.defaulturl + ISS_Constants.serviceName.DELORDER;
            $$.ajax({
                url: url,
                crossDomain: true,
                data: { content: _condition },
                method: "POST",
                success: function (data, status) {
                    data = JSON.parse(data);
                    //关闭模态窗
                    myApp.hidePreloader();
                    //关闭详情popup窗口
                    if (orderType == "0") {
                        myApp.closeModal('.popup-scenic');
                    } else if (orderType == "1") {
                        myApp.closeModal('.popup-hotel');
                    } else if (orderType == "2") {
                        myApp.closeModal('.popup-line');
                    } else if (orderType == "22") {
                        myApp.closeModal('.popup-group');
                    }
                    //提示
                    if (data.success == true && data.datas == "OK") {
                        //提示成功
                        myApp.alert('删除成功', function () {
                            //重新加载主界面
                            LoadOrderAll(1, 2);
                            myApp.showTab("#sub_orderList_tab3");
                        });
                    } else {
                        //提示失败
                        myApp.alert('删除失败！', function () {
                            //重新加载主界面
                            LoadOrderAll(1, 2);
                            myApp.showTab("#sub_orderList_tab3");
                        });
                    };
                },
                error: function (xhr, status) {
                    myApp.hidePreloader();
                    myApp.alert('参数错误!');
                }
            });
        });
    })

    //格式化数据
    function formatData(result) {
        result.statusName = ""; //状态中文
        result.statusClass = ""; //状态前台css类
        var STATUS = result.orderSTATUS;
        switch (STATUS) {
            case 1:
                result.statusName = "待确认";
                break;
            case 2:
                {
                    result.statusName = "待付款";
                    var orderTime30 = ISS.utils.strToDate(result.orderTime);
                    orderTime30 = orderTime30.setMinutes(orderTime30.getMinutes() + 30);
                    if ((orderTime30 - new Date().getTime()) > 0) {
                        //未超时数据
                        result.statusClass = "dfk";
                    }
                    else {
                        result.statusClass = "ycs";
                    }
                }
                break;
            case 3:
                result.statusName = "已取消";
                break;
            case 4:
                result.statusName = "已支付";
                result.statusClass = "yfk";
                break;
            case 5:
                result.statusName = "出票中";
                break;
            case 6:
                result.statusName = "未消费";
                break;
            case 7:
                result.statusName = "已消费";
                result.statusClass = "used";
                break;
            case 8:
                result.statusName = "退款申请中";
                result.statusClass = "sqtk";
                break;
            case 9:
                result.statusName = "退款拒绝";
                break;
            case 10:
                result.statusName = "退款中";
                break;
            case 11:
                result.statusName = "已退款";
                break;
            case 12:
                result.statusName = "预支付成功";
                break;
            case 13:
                result.statusName = "已入住";
                break;
            case 14:
                result.statusName = "提前退房申请";
                break;
            case 15:
                result.statusName = "提前退房通过";
                break;
            case 16:
                result.statusName = "提前退房拒绝";
                break;
            case 17:
                result.statusName == "退货申请中";
                break;
            case 18:
                result.statusName = "已发货";
                break;
            case 19:
                result.statusName = "已签收";
                break;
            case 20:
                result.statusName = "退货同意";
                break;
            case 21:
                result.statusName = "退货中";
                break;
            case 22:
                result.statusName = "退款审核中";
                break;
            case 23:
                result.statusName = "退货拒绝";
                break;
            case 24:
                result.statusName = "财务退款中";
                break;
            case 25:
                result.statusName = "提前退房财务退款中";
                break;
            default:
                result.statusName = "完成";
        }
        return result;
    }

});

// 抢购
var contactsCallback_pborderlist = myApp.onPageInit('pborderlist', function (page) {
    // 全局变量
    var _userID = iss_localStorage.get("yuqing_appUserId");
    //点击第一次页面执行
    var flag_order_tab1 = true;
    //当前tab标签，0：已付款 1：待付款 2：全部
    var current_tabindex = 2;
    //定义每页的页数
    var size = 10;
    //每个tab的当前页
    var index_tab0 = 1;
    var index_tab1 = 1;
    var index_tab2 = 1;
    //删除滚动后重新添加滚动
    var flag_InfiniteScroll = true;
    //是否需要滚动加载
    var flag_needScroll = true;
    //滚动事件只执行一次
    var flag_execute = false;
    //第一次加载显示index_tab1，已付款的
    if (flag_order_tab1 == true) {
        LoadOrderAll(index_tab0, current_tabindex);
        flag_order_tab1 = false;
    }

    //订单类型切换
    $$(".sub_buttons_row a").click(function () {
        $$('.infinite-scroll').scrollTop(0);
        current_tabindex = $$(this).index();
        //加载无限滚动事件
        myApp.attachInfiniteScroll($$('.infinite-scroll'));
        if ($$(this).index() == 0) {
            current_tabindex = 2;
            LoadOrderAll(index_tab0, current_tabindex);
        }
        else if ($$(this).index() == 1) {
            current_tabindex = 1;
            LoadOrderAll(index_tab1, current_tabindex);
        }
        else if ($$(this).index() == 2) {
            current_tabindex = 100;
            LoadOrderAll(index_tab2, current_tabindex);
        }
    });

    function LoadOrderAll(index, currenttab) {
        var _content = JSON.stringify(
            {
                AccountGuid: iss_localStorage.get("yuqing_appAccount"),
                OpenId: iss_localStorage.get("yuqing_appOpenId"),
                OrderStatus: currenttab
            });
        $$.ajax({
            url: ISS_Constants.Url.const_weixin_TickePanicBuying_Order_get,
            data: { conditionParm: _content },
            crossDomain: true,
            dataType: "json",
            success: function (data, status) {
                //data = JSON.parse(data.datas);
                data.datas = data.datas != null ? pdorderlistdata(data.datas) : data.datas;
                var searchTemplate = $$('#template-pborderlist-ticket').html();
                if (searchTemplate) {
                    var compiledTemplate = Template7.compile(searchTemplate);
                    var html = compiledTemplate(data);
                    html = html.trim() == "" ? "<div style='text-align: center;'>没有查询到抢购的订单</div>" : html;

                    myApp.detachInfiniteScroll($$('.infinite-scroll'));
                    if (currenttab == 2) {
                        $$('.infinite-scroll-preloader1').remove();
                        $$("#sub_pborderlist_tab1 .list-block ul").html("");
                        $$("#sub_pborderlist_tab1 .list-block ul").html(html);
                    } else if (currenttab == 1) {
                        $$('.infinite-scroll-preloader2').remove();
                        $$("#sub_pborderlist_tab2 .list-block ul").html("");
                        $$("#sub_pborderlist_tab2 .list-block ul").html(html);
                    } else {
                        $$('.infinite-scroll-preloader3').remove();
                        $$("#sub_pborderlist_tab3 .list-block ul").html("");
                        $$("#sub_pborderlist_tab3 .list-block ul").html(html);
                    }
                }
            }
        })

    }

    $$("#pborderlist_page .page-content ul ").on("click", "li", function () {
        var orderno = $$(this).attr("orderno");
        var _content = JSON.stringify({
            OrderNo: orderno
        });
        myApp.showPreloader();
        $$.ajax({
            url: ISS_Constants.Url.const_weixin_TickePanicBuying_OrderDetail_get,
            data: { conditionParm: _content },
            crossDomain: true,
            method: "POST",
            success: function (data, status) {
                try {

                    data = JSON.parse(data);
                    if (data.datas != null) {
                        data.datas[0].CreateTime = toDateFormat(data.datas[0].CreateTime);
                        data.datas[0].PanicBuyingActiveName = $$('.item-title').html().trim();
                        //中间数据模板
                        var searchTemplate = $$('#template-ticketorder-detail').html();
                        if (searchTemplate) {
                            var compiledTemplate = Template7.compile(searchTemplate);
                            var html = compiledTemplate(data.datas[0]);
                            $$(".popup-scenic div.popup-main").html(html);
                        }


                        myApp.hidePreloader();
                        myApp.popup('.popup-scenic');
                    }
                    else {
                        myApp.hidePreloader();
                        myApp.alert('参数错误!');
                    }
                } catch (ex) {
                    myApp.hidePreloader();
                }
            },
            error: function (xhr, status) {
                myApp.hidePreloader();
                myApp.alert('参数错误!');
            }
        });
    })
})
//订单详情
var contactsCallback_orderDetail = myApp.onPageInit('orderDetail', function (page) {
    //返回news页面
    $$("#orderDetail_page").on("click", "a[data-action='back']", function () {
        var href = $$(this).attr("data-href");
        if (href && href != "") {
            window.location.href = href;
        }
    });
    //获取页面参数
    var code = ISS.utils.getParameter("code");

    $$.ajax({
        url: ISS_Constants.Url.defaulturl + ISS_Constants.serviceName.ORDERS,
        crossDomain: true,
        data: "content={Code:\"" + code + "\",type:\"1\"}",
        dataType: "jsonp",
        method: "POST",
        success: function (data, status) {
            data = JSON.parse(data);
            if (data && data.status == "0") {

                var STATUS = data.results.orderSTATUS;
                switch (STATUS) {
                    case 1:
                        data.results.orderSTATUS = "待确认";
                        break;
                    case 2:
                        data.results.orderSTATUS = "待付款";
                        break;
                    case 3:
                        data.results.orderSTATUS = "已取消";
                        break;
                    case 4:
                        data.results.orderSTATUS = "已支付";
                        break;
                    case 5:
                        data.results.orderSTATUS = "出票中";
                        break;
                    case 6:
                        data.results.orderSTATUS = "未消费";
                        break;
                    case 7:
                        data.results.orderSTATUS = "已消费";
                        break;
                    case 8:
                        data.results.orderSTATUS = "退款申请中";
                        break;
                    case 9:
                        data.results.orderSTATUS = "退款拒绝";
                        break;
                    case 10:
                        data.results.orderSTATUS = "退款中";
                        break;
                    case 11:
                        data.results.orderSTATUS = "已退款";
                        break;
                    case 12:
                        data.results.orderSTATUS = "预支付成功";
                        break;
                    case 13:
                        data.results.orderSTATUS = "已入住";
                        break;
                    case 14:
                        data.results.orderSTATUS = "提前退房申请";
                        break;
                    case 15:
                        data.results.orderSTATUS = "提前退房通过";
                        break;
                    case 16:
                        data.results.orderSTATUS = "提前退房拒绝";
                        break;
                    case 17:
                        data.results.orderSTATUS == "退货申请中";
                        break;
                    case 18:
                        data.results.orderSTATUS = "已发货";
                        break;
                    case 19:
                        data.results.orderSTATUS = "已签收";
                        break;
                    case 20:
                        data.results.orderSTATUS = "退货同意";
                        break;
                    case 21:
                        data.results.orderSTATUS = "退货中";
                        break;
                    case 22:
                        data.results.orderSTATUS = "退款审核中";
                        break;
                    case 23:
                        data.results.orderSTATUS = "退货拒绝";
                        break;
                    case 24:
                        data.results.orderSTATUS = "财务退款中";
                        break;
                    case 25:
                        data.results.orderSTATUS = "提前退房财务退款中";
                        break;
                    default:
                        data.results.orderSTATUS = "完成";
                }

                var searchTemplate = $$('#template-resturant-detail').html();
                var compiledSearchTemplate = Template7.compile(searchTemplate);
                var html = compiledSearchTemplate(data.results);
                $$("#sub_orderDetail_tab").html(html);

                //酒店
                if (data.results.getHotelOrderInfo.length > 0) {
                    for (var i = 0; i < data.results.getHotelOrderInfo.length; i++) {
                        var timer = data.results.getHotelOrderInfo[i].createDate.split(" ");
                        if (timer.length > 0) {
                            data.results.getHotelOrderInfo[i].createDate = timer[0];
                        }
                    }

                    var searchTemplate1 = $$('#template-orderDetail-tabHotel').html();
                    if (searchTemplate1) {
                        var compiledTemplate1 = Template7.compile(searchTemplate1);
                        var html = compiledTemplate1(data.results);
                        $$("#sub_orderDetail_tabHotel").append(html);
                    }
                }

                //线路
                if (data.results.getLineOrderInfo.length > 0) {
                    for (var i = 0; i < data.results.getLineOrderInfo.length; i++) {
                        var timer = data.results.getLineOrderInfo[i].createDate.split(" ");
                        if (timer.length > 0) {
                            data.results.getLineOrderInfo[i].createDate = timer[0];
                        }
                    }

                    var searchTemplate1 = $$('#template-orderDetail-tabLine').html();
                    if (searchTemplate1) {
                        var compiledTemplate1 = Template7.compile(searchTemplate1);
                        var html = compiledTemplate1(data.results);
                        $$("#sub_orderDetail_tabLine").append(html);
                    }
                }

                //门票
                if (data.results.getTicketOrderInfo.length > 0) {
                    for (var i = 0; i < data.results.getTicketOrderInfo.length; i++) {
                        var timer = data.results.getTicketOrderInfo[i].createDate.split(" ");
                        if (timer.length > 0) {
                            data.results.getTicketOrderInfo[i].createDate = timer[0];
                        }
                    }

                    var searchTemplate1 = $$('#template-orderDetail-tabTicket').html();
                    if (searchTemplate1) {
                        var compiledTemplate1 = Template7.compile(searchTemplate1);
                        var html = compiledTemplate1(data.results);
                        $$("#sub_orderDetail_tabTicket").append(html);
                    }
                }
                //团购
                if (data.results.getGroupOrder.length > 0) {
                    for (var i = 0; i < data.results.getGroupOrder.length; i++) {
                        var timer = data.results.getGroupOrder[i].createDate.split(" ");
                        if (timer.length > 0) {
                            data.results.getTicketOrderInfo[i].createDate = timer[0];
                            data.results.getGroupOrder[i].createDate = toDateFormat(data.results.getGroupOrder[i].createDate);
                            data.results.getGroupOrder[i].toDay = toDateFormat(data.results.getGroupOrder[i].toDay);
                        }
                    }

                    var searchTemplate1 = $$('#template-orderDetail-tabTicket').html();
                    if (searchTemplate1) {
                        var compiledTemplate1 = Template7.compile(searchTemplate1);
                        var html = compiledTemplate1(data.results);
                        $$("#sub_orderDetail_tabTicket").append(html);
                    }
                }

            }
        },
        error: function (xhr, status) {
            console.log("ajax error!");

        }
    });
});




function initData() {
    var href = window.location.href;
    if (href.indexOf(orderList) > -1) {
        contactsCallback_orderList.trigger();
    }
    else if (href.indexOf(orderDetail) > -1) {
        contactsCallback_orderDetail.trigger();
    } else if (href.indexOf(pborderlist) > -1) {
        contactsCallback_pborderlist.trigger();
    }
}

initData();

function checkTime(k) {
    if (k < 10) {
        k = "0" + k;
    }
    return k;
}

function toDateFormat(date) {
    if (date.length > 10) {
        date = date.substring(0, 10);
    }
    if (date.indexOf('-') > 0) {
        date = date.replace(/-/g, ".");
    }
    return date;
}

function toDateFormatFull(date) {
    if (date.indexOf('-') > 0) {
        date = date.replace(/-/g, ".");
    }
    return date;
}

function pdorderlistdata(datalist) {
    for (var i = 0; i < datalist.length; i++) {
        if (datalist[i].OrderStatus == 1) {
            datalist[i].CNOrderStatus = "未付款";
        } else if (datalist[i].OrderStatus == 2) {
            datalist[i].CNOrderStatus = "已付款";
        }

        datalist[i].PanicBuyingBeginTime = ISS.utils.dateToStr("yyyy-MM-dd hh:mm", new Date(ISS.utils.ReplaceHMS(datalist[i].PanicBuyingBeginTime)));
    }

    return datalist;
}